/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package form.components;

import com.sun.lwuit.Component;
import com.sun.lwuit.Image;
import com.sun.lwuit.Label;
import com.sun.lwuit.List;
import com.sun.lwuit.list.ListCellRenderer;
import com.sun.lwuit.plaf.Border;
import domain.model.ICategoria;
import view.img.ImageStore;

/**
 *
 * @author ademar.victorino
 */
public class CategoriaListRenderer extends Label implements ListCellRenderer {

    public Component getListCellRendererComponent(List list,
            Object value, int index, boolean isSelected) {

        this.getStyle().setBorder(Border.createRoundBorder(4, 2));

        ICategoria cat = (ICategoria) value;
        String label = cat.getNome();
        setText(label);

        Image img = null;
        if (cat.getCategoriaPaiId() == -1) {
            if (label.toLowerCase().equals("Saúde".toLowerCase())) {
                img = ImageStore.getInstance().getImage("Saude");
            } else if (label.toLowerCase().equals("Serviços".toLowerCase())) {
                img = ImageStore.getInstance().getImage("Servicos");
            } else if (label.toLowerCase().equals("Indústria".toLowerCase())) {
                img = ImageStore.getInstance().getImage("Industria");
            } else if (label.toLowerCase().equals("Comércio".toLowerCase())) {
                img = ImageStore.getInstance().getImage("Comercio");
            } else if (label.toLowerCase().equals("Onde Dormir/Ficar".toLowerCase())) {
                img = ImageStore.getInstance().getImage("Dormir");
            } else if (label.toLowerCase().equals("Onde Comer".toLowerCase())) {
                img = ImageStore.getInstance().getImage("Comer");
            } else if (label.toLowerCase().equals("Lista Alfabética".toLowerCase())) {
                img = ImageStore.getInstance().getImage("geral");
            } else if (label.toLowerCase().equals("Telefones Úteis".toLowerCase())) {
                img = ImageStore.getInstance().getImage("telUtil");
            } else if (label.toLowerCase().equals("Disk Entrega".toLowerCase())) {
                img = ImageStore.getInstance().getImage("Disk");
            }
        }

        if (isSelected) {
            getStyle().setBgColor(0xffcc66);
            if (img == null) {
                img = ImageStore.getInstance().getImage("registro");
            }
        } else {
            getStyle().setBgColor(0xcccccc);
            if (img == null) {
                img = ImageStore.getInstance().getImage("categoriaDefault");
            }
        }
        if (img != null) {
            setIcon(img);
        }
        return this;
    }

    public Component getListFocusComponent(List list) {
        Label label = new Label("");
        label.getStyle().setBgTransparency(100);
        return label;
    }
}

